<?php
/**
 * oci access helper functions
 *
 */
 
function oci_query($sql_text) 
{
 	return oci_query_impl('springs', 'sc123456', '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.113)(PORT = 1521)))(CONNECT_DATA =(SID = orcl)(SERVER = DEDICATED)))', $sql_text);
}

function oci_query_finchina($sql_text) 
{
	return oci_query_impl('fcdb', 'fcdb', '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.98)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = winddb)))', $sql_text);
}

function oci_query_impl($usr, $pwd, $connection_str, $sql_text) 
{
 	$conn = oci_connect($usr, $pwd, $connection_str, 'AL32UTF8');
	if (!$conn) {
	    $e = oci_error();
	    trigger_error($e['message'], E_USER_ERROR);
	}
	
	// Prepare the statement
	$stid = oci_parse($conn, $sql_text);
	if (!$stid) {
	    $e = oci_error($conn);
	    //trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);    
	    trigger_error($e['message'], E_USER_ERROR);    
	}
	
	// Perform the logic of the query
	$r = oci_execute($stid);
	if (!$r) {
	    $e = oci_error($stid);
	    //trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
	    trigger_error($e['message'], E_USER_ERROR);
	}
	
	// Fetch the results of the query
	$status = oci_fetch_all($stid, $result, 0, -1, OCI_FETCHSTATEMENT_BY_ROW+OCI_NUM); 

	oci_free_statement($stid);
	oci_close($conn);
	return $result;
}